package XishiBackend.controllers.microsite;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import XishiBackend.base.Constant;
import XishiBackend.base.Json;
import XishiBackend.models.entity.Dishes;
import XishiBackend.services.microsite.MicrositeDishesService;

@RestController
@EnableAutoConfiguration
@RequestMapping("/microsite/dishes")
public class MicrositeDishesController {
    @Autowired
    private MicrositeDishesService dS;
    
    @RequestMapping(value = "/alldishestype",method=RequestMethod.POST)
    public String alldishestype(@RequestParam("sig") String sig){
        Map<String,String> dtmap = dS.findDishesType();
        return Json.format(0, "获取菜品分类成功", dtmap);
    }
    
    @RequestMapping(value = "/allrecommandtype",method=RequestMethod.POST)
    public String allrecommandtype(@RequestParam("sig") String sig) {
        Map<String,String> rtmap = new HashMap<String,String>();
        for(int i = 0;i < Constant.RECOMMAND_TYPE.length;i++) {
            rtmap.put("" + i, Constant.RECOMMAND_TYPE[i]);
        }
        return Json.format(0, "获取推荐分类成功", rtmap);
    }
    
    @RequestMapping(value = "/alldishes",method=RequestMethod.POST)
    public String alldishes(@RequestParam("sig") String sig){
        //获取全部菜品
        List<Dishes> dList = dS.findAll();
        //获取菜品分类
        Map<String,String> dtmap = dS.findDishesType();
        //返回结果
        Map<String, Object> r = new HashMap<String,Object>();
        r.put("dishes", dList);
        r.put("dishesType", dtmap);
        return Json.format(0, "获取全部菜品成功", r);
    }
}
